package com.xxzuibang.day16.stringbuilder类;

public class Compare {
    public static void main(String[] args) {
        //比较String，StringBuffer，StringBuilder
        //结论：  效率：StringBuilder>StringBuffer>String
        long startTime = 0L;
        long endTime = 0L;
        StringBuffer stringBuffer = new StringBuffer("");
        startTime = System.currentTimeMillis();
        for (int i = 0; i < 80000; i++) {
            stringBuffer.append(String.valueOf(i));
        }
        endTime = System.currentTimeMillis();
        System.out.println("StringBuffer的执行时间:" + (endTime - startTime));

        StringBuilder stringBuilder = new StringBuilder("");
        startTime = System.currentTimeMillis();
        for (int i = 0; i < 80000; i++) {
            stringBuilder.append(String.valueOf(i));
        }
        endTime = System.currentTimeMillis();
        System.out.println("StringBuilder的执行时间:" + (endTime - startTime));

        String text="";
        startTime=System.currentTimeMillis();
        for (int i = 0; i < 80000; i++) {
            text+=i;
        }
        endTime=System.currentTimeMillis();
        System.out.println("String的执行时间:" + (endTime - startTime));


    }
}
